<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let input = `5 6
1 2 0
1 2 1
1 5 0
2 3 1
2 5 1
1 3 2`

        let list = input.split('\n')
        let [n, m] = list.shift().split(' ').map(v => parseInt(v.trim()))
        list = list.map(v => v.split(' ').map(j => parseInt(j.trim())))

        let obj = {}
        let visited = new Set()
        let save = []
        
        for (let i = 0; i < list.length; i++) {
            if (list[i][2] > 1) {
                save.push(i)
                continue
            }
            if (list[i][2] === 0) {
                for (let j = 0; j < list.length; j++) {
                    if(i==j){
                        continue
                    }
                    if (list[j][0] === list[i][1]) {
                        list[j][0] = list[i][0]
                    }
                    if (list[j][1] === list[i][1]) {
                        list[j][1] = list[i][0]
                    }
                }
            }
            if (list[i][2] === 1) {
                save.push(i)
            }
        }
        while(save.length){
            let i=save.shift()
            if(list[i][2]>1){

                console.log('da pian zi '); 
            }else if(list[i][1]===list[i][0]){
                console.log('we are a team');                
            }else if(list[i][1]!==list[i][0]){
                console.log('we are not a team ');
                
            }
        }
 


        console.log([n, m]);
        console.log(list);
        console.log(save);
        



    </script>
</body>

</html>